import request from '@/utils/request.js'
import { useTokenStore } from "@/stores/token.js";

const baseURL = 'http://8.130.42.115:8000'
//管理員修改自己的密碼

export const changePassword = (params) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/admin/changePassword', null, { headers, params })
}

//学生列表查询
export const allSudentInfoService = async () => {
    const store = useTokenStore()
    const headers = store.token
    console.log(headers)
    // console.log(store.token.token,'token')
    return request.get(baseURL + '/student/findall', { headers });
}
//学生模糊查询
export const selectSudentInfoService = (data) => {
    let params = new URLSearchParams()
    params.append('pageNum', data.pageNum);
    params.append('pageSize', data.pageSize);
    if (data.studentID) {
        params.append('studentID', data.studentID);
    }
    if (data.name) {
        params.append('name', data.name);
    }
    const store = useTokenStore()
    const headers = store.token
    return request.get('/student/page1', {
        headers,
        params
    });
}
//学生信息编辑
export const editorStudentInfo = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/admin/updatestudentpassword', data, { headers })
}
//学生密码修改
// export const changeStudentPswService = (studentID, password, token) => {
//     let headers = {
//         'token': token
//     };
//     let body = {
//         studentID: studentID,
//         password: password
//     }
//     return axios.post(baseURL + '/admin/updatestudentpassword', body, headers)
//         .then(response => {
//             return response.data;
//         })
//         .catch(error => {
//             console.error('There has been a problem with your fetch operation:', error);
//             throw error;
//         });
// }
//学生单个删除
export const deleteSingleStudent = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.delete(baseURL + `/student/${data}`, { headers })
}
//学生批量删除
export const deleteBatchStudents = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/student/del/batch', data, { headers })
}
//學生單個課堂内的刪除
export const deleteSingleStudentInClass = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.delete(baseURL + `/student/${data.classID}/${data.studentID}`, { headers })
}
//學生批量課堂内的刪除
export const deleteBatchStudentsInClass = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/student/classstu/del/batch', data, { headers })
}

//学生单个增加
export const addSingleStudent = (data) => {
    const store = useTokenStore()
    const headers = store.token
    if (data.classID) {
        let params = new URLSearchParams()
        params.append('classID', data.classID);
        delete data.classID

        return request.post(baseURL + `/student/save`, data, { headers, params })
    }
    else {
        return request.post(baseURL + '/student/save', data, { headers })
    }
}
//学生批量增加
export const addStudentsService = (data) => {

}
//学生加入的课堂
export const allCourseStudentAttend = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + `/admin/findalljoin/${data}`, { headers })
}
// //学生移出课堂
export const removeStudentFromCourse = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.delete(baseURL + `/student/${data.classID}/${data.studentID}`, { headers })
}

//学生课堂列表查询
export const allChapterInfoService = () => {
    //return request.get('/student/getClassChapterInfo');
}
//老师列表查询
export const allTeacerInfoService = () => {
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + '/teacher/findall', { headers });
}
//老师单个添加
export const addSingleTeacher = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/admin/save', data, { headers })
}
//老师单个删除
export const deleteSingleTeacher = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.delete(baseURL + `/teacher/${data}`, { headers })
}
//老师批量删除
export const deleteBatchTeachers = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/teacher/del/batch', data, { headers })
}
//老師批量導入
export const uploadTeacher = (file) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/teacher/upload', file, { headers })
}
//老师信息修改
export const editorTeacherInfo = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/admin/update', data, { headers })
}
//老师模糊查找
export const searchTeacher = (data) => {
    let params = new URLSearchParams()
    params.append('pageNum', data.pageNum);
    params.append('pageSize', data.pageSize);
    if (data.teacherID) {
        params.append('teacherID', data.teacherID);
    }
    if (data.name) {
        params.append('name', data.name);
    }
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + '/teacher/page2', { headers, params })
}
//教师创建的课堂
export const classOfTeacher = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + `/admin/findallcreate/${data}`, { headers })
}
//教师加入的课程
export const classAttendOfTeacher = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + `/admin/findalljoinforteacher/${data}`, { headers })
}
//教師移出加入的課堂
export const removeTeacherFromCourse = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.delete(baseURL + `/admin/${data.classID}/${data.teacherID}`, { headers })
}

//课程列表查询
export const allCourseInfoService = async () => {
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + '/admin/findallcourse', { headers });
}
//课程信息修改
export const editorCourseInfo = (params) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/course/saveorupdate', null, { headers, params })
}
//课程单个删除
export const deleteSingleCourse = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.delete(baseURL + `/course/${data}`, { headers })
}
//课程批量删除
export const deleteBatchCourses = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/course/del/batch', data, { headers })
}
//课程单个添加
export const addSingleCourse = (params) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/course/saveorupdate', null, { headers, params })
}
//课程模糊查询
export const selectCourse = (data) => {
    let params = new URLSearchParams()
    params.append('pageNum', data.pageNum);
    params.append('pageSize', data.pageSize);
    if (data.courseID) {
        params.append('courseID', data.courseID);
    }
    if (data.name) {
        params.append('name', data.name);
    }
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + '/admin/course/page2', { headers, params })
}
//课程添加章节
export const addChapter = (params,data) => {
    // let params = new URLSearchParams()
    // params.append('courseName', courseName);
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/admin/savechapter', data,{ headers, params })
}

//课堂模糊查询----还要加很多参数校验在table里
export const allClassInfoService = (data) => {
    let params = new URLSearchParams()
    params.append('pageNum', data.pageNum);
    params.append('pageSize', data.pageSize);
    if (data.classID) {
        params.append('classID', data.classID);
    }
    if (data.name) {
        params.append('className', data.className);
    }
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + '/teacher/pageforclass', { headers, params })
}
//课堂信息编辑
export const editorClassInfo = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.post(baseURL + '/teacher/update/class', data, { headers })
}
//课堂下的所有学生
export const findallStudentByClass = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + `/student/findallstudentbyclass/${data}`, { headers })
}
//课堂的授课老师
export const findallTeacherByClass = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + `/teacher/findallteacher/${data}`, { headers })

}
//課堂助教
export const findallTAByClass = (data) => {
    const store = useTokenStore()
    const headers = store.token
    return request.get(baseURL + `/teacher/findallTA/${data}`, { headers })

}